package com.japp.sys.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.japp.base.BaseAction;
import com.japp.sys.bean.RoleBean;
import com.japp.sys.service.RoleService;
@Scope("prototype")
@Controller
public class RoleAction extends BaseAction<RoleBean> {

	private static final long serialVersionUID = 1L;
	@Autowired
	private RoleService roleService;
	private RoleBean role = new RoleBean();
	
	/**
	 * 查询所有角色
	 * @return
	 */
	public String queryRoleAll() {
		return SUCCESS;
	}
	/**
	 * 分页查询
	 * @return
	 */
	public String queryRole(){
		page = roleService.getPage(page, role);
		return SUCCESS;
	}
	/**
	 * 查询角色（ID）
	 * @return
	 */
	public String findRoleById() {
		return SUCCESS;
	}
	/**
	 * 更新角色
	 * @return
	 */
	public void updateRoleById() {
		int rel = 0;
		if(role.getR_id()!=0){
			rel = roleService.updateRole(role);
		}
		if(rel==999){
			result = "角色名称已存在!";
		}else if(rel!=0){
			result = "角色修改成功!";
		}else{
			result = "角色修改失败!";
		}
		wPrint(result);
	}
	/**
	 * 添加角色
	 * @return
	 */
	public void insertRoleById() {
		int rel = roleService.insertRole(role);
		if(rel==999){
			result = "角色名“"+role.getR_name()+"”已存在!";
		}else if(rel!=0){
			result = "角色“"+role.getR_name()+"”新增成功!";
		}else{
			result = "角色“"+role.getR_name()+"”新增是失败!";
		}
		wPrint(result);
	}
	/**
	 * 删除角色
	 * @return
	 */
	public void deleteRoleById() {
		int rel = roleService.deleteRoleById(keys);
		if(rel!=0){
			result = "角色删除成功!";
		}else{
			result = "角色删除失败!";
		}
		wPrint(result);
	}
	
	public RoleBean getRole() {
		return role;
	}
	public void setRole(RoleBean role) {
		this.role = role;
	}
	
}
